package sg.edu.nus.comp.icreate.ivletalk.events;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.protocol.HTTP;

import sg.edu.nus.comp.icreate.ivletalk.EventNoRefreshBaseActivity;
import sg.edu.nus.comp.icreate.ivletalk.R;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListEventElementActivity extends EventNoRefreshBaseActivity {

	private Event event;
	private int position;
	public List<String> result = new ArrayList<String>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_list_element);
		position = getIntent().getIntExtra(DisplayEvents.EXTRA_NAME_EVENT_POSITION, 0);

		event = DisplayEvents.events.get(position);
		result.add("Title: " + event.getTitle());
		if (event.getDate() == null) {
			result.add("Date: ");
		} else {
			result.add("Date: " + event.getDate());
		}
		result.add("Organizer: " + event.getOrganizer());
		if (event.getVenue() == null) {
			result.add("Venue: ");
		} else {
			result.add("Venue: " + event.getVenue());
		}

		if (event.getPrice() == null) {
			result.add("Price: ");
		} else {
			result.add("Price: " + event.getPrice());
		}
		if (event.getContact() == null) {
			result.add("Contact: ");
		} else {
			result.add("Contact: " + event.getContact());
		}
		result.add("Description: ");

		setContentView(R.layout.activity_list_element);
		setTitle(event.getTitle());
		WebView eventWebView = (WebView) findViewById(R.id.eventWebView);
		String customHtml = event.getDescription();
		eventWebView.loadData(customHtml, "text/html", HTTP.UTF_8);

		ListView eventText = (ListView) findViewById(R.id.eventelementList);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, result);
		eventText.setAdapter(adapter);
	}
}
